//
//  UIColor+Ex.m
//  iOSCodeLearning
//
//  Created by TFAppleWork-Summer on 2018/3/14.
//  Copyright © 2018年 Ace. All rights reserved.
//

#import "UIColor+Ex.h"

@implementation UIColor (Ex)
+ (UIColor *)randomColor {
    NSInteger aRedValue = arc4random() % 255;
    NSInteger aGreenValue = arc4random() % 255;
    NSInteger aBlueValue = arc4random() % 255;
    UIColor *randColor = [UIColor colorWithRed:aRedValue / 255.0f green:aGreenValue / 255.0f blue:aBlueValue / 255.0f alpha:1.0f];
    return randColor;
}


+(UIColor *)colorWithHexString:(NSString *)color{
    
    return  [self colorWithHexString:color alpha:1];
}

+(UIColor *)colorWithHexString:(NSString *)hexColor alpha:(CGFloat)alpha{
    //剔除#
    hexColor = [hexColor stringByReplacingOccurrencesOfString:@"#" withString:@""];
    unsigned int red, green, blue;
    NSRange range;
    range.length =2;
    
    range.location =0;
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&red];
    range.location =2;
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&green];
    range.location =4;
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&blue];
    
    return [UIColor colorWithRed:(float)(red/255.0f)
                           green:(float)(green/255.0f)
                            blue:(float)(blue/255.0f)
                           alpha:alpha];
}



@end
